package com.atguigu.gmall.product.service.impl;

import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.product.mapper.BaseTrademarkMapper;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author ：Shine
 * @description：
 * @date ：2021/2/2 20:35
 */

@Service
public class BaseTrademarkServiceImpl extends ServiceImpl<BaseTrademarkMapper, BaseTrademark> implements BaseTrademarkService {

    @Autowired
    private BaseTrademarkMapper baseTrademarkMapper;

    @Override
    public IPage<BaseTrademark> getPage(Page<BaseTrademark> pageParam) {

        //构件查询对象，将查询结果降序排序
        QueryWrapper<BaseTrademark> orderByDescId = new QueryWrapper<BaseTrademark>().orderByDesc("id");
        return baseTrademarkMapper.selectPage(pageParam, orderByDescId);

    }

    @Override
    public List<BaseTrademark> findBaseTrademarkByKeyword(String keyword) {
        QueryWrapper<BaseTrademark> baseTrademarkQueryWrapper = new QueryWrapper<>();
        baseTrademarkQueryWrapper.like("tm_name", keyword);
        return baseTrademarkMapper.selectList(baseTrademarkQueryWrapper);
    }

    @Override
    public List<BaseTrademark> findBaseTrademarkByTrademarkIdList(List<Long> trademarkIdList) {
        return baseTrademarkMapper.selectBatchIds(trademarkIdList);
    }
}
